#!/bin/env python3
# -*- coding:utf-8 -*-
"""
    [模块名]
    Add By : cdj <e4ting@qq.com> 2021-07-14 17:57:18
"""
from flask_restful import Resource
from flask         import redirect,request,make_response

from e4ting import util,log


# @webcore.api("/v3/url2img", "/v3/url2img/", "/v3/url2img/<string:fname>")
class Url2Img(Resource):
    """ url 转图片 """
    def get(self, fname=None):
        import url2img
        output = "/tmp/test.png"

        url = request.args.get("url", None)
        if not url:
            return {
                "code" : 400,
                "msg"  : "参数错误"
            }

        url = url.strip()
        log.info("output", url)

        ret = url2img.url_to_img(url, output)
        return {
            "code" : 200,
            "data"  : output,
        }
